package com.yanqu.road.server.cmd.systemgroup;

import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross.group.CrossGroupProto;
import com.yanqu.road.pb.worldmessage.WorldMessageProto;
import com.yanqu.road.server.cmd.CrossAppointCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.systemgroup.Cross2SystemWeekGroupMatchMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C2_SYSTEM_GROUP_CHAT_LIST, desc = "系统跨服分组聊天列表")
public class SystemCrossGroupChatListCmd extends CrossAppointCommand {
    private long userId;
    int groupId;
    int systemId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossGroupProto.SystemCrossGroupChatListReqMsg reqMsg = CrossGroupProto.SystemCrossGroupChatListReqMsg.parseFrom(packet.getBytes());
        groupId = reqMsg.getGroupId();
        systemId = reqMsg.getSystemId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        userId = packet.getPlayerId();
        int weekId = GameConfig.getSystemThisWeekId();
        WorldMessageProto.WorldMessageListMsg.Builder msg = Cross2SystemWeekGroupMatchMgr.getChatListMsg(weekId, systemId, groupId);
        if(null == msg){
            msg = WorldMessageProto.WorldMessageListMsg.newBuilder();
        }
        CrossGroupProto.SystemCrossGroupChatListRespMsg.Builder respMsg = CrossGroupProto.SystemCrossGroupChatListRespMsg.newBuilder();
        respMsg.setGroupId(groupId);
        respMsg.setSystemId(systemId);
        respMsg.setDataList(msg);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.S_CROSS_SYSTEM_GROUP_CHAT_LIST_NOTIFY, respMsg);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }

    @Override
    public void sendData() {

    }
}
